/**
 * PasswordMask.java 2008-05-14
 * 
 * Linker is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

package linker.account;

/**
 * A mask to make a change of the password to save. It will avoid the simplest
 * way to steal your password. But because this is an open source application,
 * actually it makes no contribution to the security of your saved password
 * 
 * @version 2008-05-16
 * @author Jianfeng tujf.cn@gmail.com
 * @author AwakenRz awakenrz@gmail.com
 * 
 */

public final class PasswordMask {

	/**
	 * The default blank constructor.
	 */
	private PasswordMask() {
	}

	/**
	 * The password mask.
	 */
	private static String mask = "asdfghjklpom inubyvtcrxewzqQASW"
			+ "EDFRVCZTGBXNHYUJKIOPLM0123498765#";

	/**
	 * Change code to password.
	 * 
	 * @param code
	 *            The code to be changed to password.
	 * @return Password.
	 */
	public static String getPassword(final String code) {
		char[] codes = code.toCharArray();

		for (int i = 0; i < codes.length; i++) {
			codes[i] = mask.charAt(mask.indexOf(codes[i]) - 1);
		}
		return new String(codes);
	}

	/**
	 * Change password to code.
	 * 
	 * @param password
	 *            The password to be changed to code.
	 * @return Code.
	 */
	public static String setPassword(final String password) {
		char[] codes = password.toCharArray();

		for (int i = 0; i < codes.length; i++) {
			codes[i] = mask.charAt(mask.indexOf(codes[i]) + 1);
		}
		return new String(codes);
	}
}
